package com.sky.controller.admin;


import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.result.PageResult;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.result.Result;
import com.sky.service.OrderService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/admin/order")
@Api(tags = "订单管理相关接口")
@Slf4j
public class OrderController {
    @Autowired
    private OrderService orderService;

    @ApiOperation("各个状态的订单数量统计")
    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> statusCount() {
        log.info("各个状态订单统计开始！");
        OrderStatisticsVO vo=  orderService.statusCount();
        return Result.success(vo);
    }


    public Result complete(@PathVariable Integer id) {
        log.info("完成订单！");
        orderService.complete(id);
        return Result.success();
    }
    /**
     * 派送订单
     *
     * @param id
     * @return
     */
    @ApiOperation(("派送订单"))
    @PutMapping("/delivery/{id}")
    public Result delivery(@PathVariable("id") Long id) {
        log.info("订单id，id={}", id);
        orderService.delivery(id);
        return Result.success();
    }


    /**
     * 订单搜索
     *
     * @return
     */
    @ApiOperation("订单搜索")
    @RequestMapping("conditionSearch")
    public Result<PageResult> conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO) {
        log.info("订单信息", ordersPageQueryDTO);
        PageResult pageResult = orderService.conditionSearch(ordersPageQueryDTO);

        return Result.success(pageResult);
    }

    /**
     * 拒绝订单
     * @param
     * @return
     */
    @ApiOperation("商家拒绝订单")
    @PutMapping("/rejection")
    public Result rejectOrder(@RequestBody OrdersRejectionDTO dto){
        log.info("拒绝订单");
        orderService.rejectOrder(dto);
        return Result.success();
    }

    /**
     * 取消订单
     * @param dto
     * @return
     */
    @ApiOperation("商家取消订单")
    @PutMapping("/cancel")
    public Result cancelOrder(@RequestBody OrdersCancelDTO dto){
        log.info("取消订单");
        orderService.cancelOrder(dto);
        return Result.success();
    }
}
